package org.itboys.portal.service;

import java.util.List;
import java.util.Map;

import org.itboys.portal.entity.PortalInfo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class InfoCacheService implements InitializingBean{
	
	@Autowired
	private PortalInfoService infoService;
	
	public static List<PortalInfo> infos = Lists.newArrayList();

	@Override
	public void afterPropertiesSet() throws Exception {
		Map<String, Object> param = Maps.newHashMapWithExpectedSize(0);
		infos = infoService.list(param);
	}
	
	public void changeInfos(PortalInfo info){
		boolean pass = true;
		for (int i = 0 ; i < infos.size() ; i ++) {
			PortalInfo portalInfo = infos.get(i);
			if(Long.valueOf(info.getId()).equals(Long.valueOf(portalInfo.getId()))){
				infos.add(i, info);
				pass = false;
				break;
			}
		}
		if(pass){
			infos.add(info);
		}
	}

}
